const db = require('../conn.js');
const r = require('../err.js');

async function getList(req, res){
	let page = 1;
	if (req.query.page) {
		page = req.query.page;
	}
	if (page < 1) {
		page = 1;
	}
	console.log(req.path+req.query.page+","+page);
	try{
		let list = await db.get('users').find({},{
			fields:'-_id -password',
			limit:10,
			skip:10*(page-1)
		});
		res.json(r.success(list));
	}catch(e){
		console.log(e);
		res.json(r.error(500,e.toString()));
	}
}
module.exports = (app)=>{
	app.route('/node/list')
		.get((req, res)=>{
			getList(req, res);
		});
};
